<?php
// @formatter:off
/**
 * @file c.collection.php
 * @author Alejandro Dario Simi
 * @date $Date: 2013-06-16 23:56:49 +0000 (Sun, 16 Jun 2013) $
 *
 * $Id: c.collection.php 73 2013-06-16 23:56:49Z daemonraco@gmail.com $
 * $URL: http://wcomix.googlecode.com/svn/tags/wcomix-1.0/themes/default/controlers/contents/c.collection.php $
 */
// @formatter:on

if($wcProfile->allowedTo(WC_PERM_COLLECTION_VIEW)) {
	require_once "{$this->_themeRoot}/controlers/generics/comicpreview.php";
	require_once "{$this->_themeRoot}/controlers/generics/bundlepreview.php";
	require_once "{$this->_themeRoot}/controlers/generics/pager.php";

	if($wcCollection && $wcCollection->ok()) {
		global $wcCollectionsHolder;

		$wcThemeAssigns["PATH"] = "{$wcCollection->name}";
		$wcThemeAssigns["ACTIONCONTENT"] = "/contents/c.collection.html";
		$wcThemeAssigns["title"] = "Collection '{$wcCollection->name}'";

		$comics = array();
		$collections = array();

		$items = $wcCollection->comics();
		uasort($items, "WCComic::NameSort");
		foreach($items as $comic) {
			$comics[] = wcGetComicPreviewAssigns($comic);
		}

		$ids = 1;
		$items = $wcCollection->collections();
		uasort($items, "WCCollection::Sort");
		foreach($items as $collection) {
			$collections[] = wcGetCollectionPreviewAssigns($collection);
		}

		$comicsCount = count($comics);
		$collectionsCount = count($collections);
		if($comicsCount) {
			$wcThemeAssigns["COMICS"] = $comics;
		}
		if($collectionsCount) {
			$wcThemeAssigns["COLLECTIONS"] = $collections;
		}

		if($wcCollection->ok() && !$wcCollection->valid_preview) {
			$wcCollection->generatePreviews();
		}

		if($wcProfile->allowedTo(WC_PERM_COLLECTION_EDIT)) {
			$wcThemeAssigns["INFO-COLL-EDITABLE"] = true;
		}
		if($wcProfile->allowedTo(WC_PERM_COLLECTION_RENAME)) {
			$wcThemeAssigns["INFO-NAME-EDITABLE"] = true;
		}
		$wcThemeAssigns["INFO-NAME"] = $wcCollection->name;
		$wcThemeAssigns["INFO-COUNT-COMIC"] = $comicsCount;
		$wcThemeAssigns["INFO-COUNT-COLLECTIONS"] = $collectionsCount;
		if($wcCollection->parent) {
			$parent = $wcCollectionsHolder->item($wcCollection->parent, $wcGroup);
			if($parent && $parent->ok()) {
				$wcThemeAssigns["INFO-COLLECTIONS"] = $parent->collectionPath();
			}
		}
	} else {
		$wcThemeAssigns["error-string"] = "Invalid collection";
		require "{$this->_themeRoot}/controlers/contents/c.500.php";
	}
} else {
	$wcThemeAssigns["error-string"] = "You're not allowed to open collections";
	require "{$this->_themeRoot}/controlers/contents/c.403.php";
}
?>
